package com.wuster.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wuster.entity.Category;
import com.wuster.result.Result;
import com.wuster.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;

import java.util.List;
import java.util.Locale;
import java.util.concurrent.Callable;

@RestController
@RequestMapping("/category")
//@Tag(name = "分类相关信息管理")
@Api(tags="分类相关信息管理")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("getCategoryDetails")
    @ApiOperation("根据ID查询分类信息")
    public Result<Category> getCategoryDetails(@Parameter(description = "分类ID") @RequestParam("categoryId") Long categoryId) {
        Category category = categoryService.getByCategoryId(categoryId);
        return Result.success(category);
    }

    @GetMapping("getAllCategory")
    @ApiOperation("获取所有分类信息")
    public Result<List<Category>> getAllCategory() {
        List<Category> list = categoryService.list();
        return Result.success(list);
    }

    @PostMapping("addCategory")
    @ApiOperation("添加分类信息")
    public Result addCategory(@RequestBody Category category) {
        //前端不传id
        categoryService.addCategory(category);
        return Result.success();
    }

    @DeleteMapping("deleteCategory")
    @ApiOperation("根据id删除分类")
    public Result deleteCategory(@RequestParam Long categoryId) {
        categoryService.deleteCategory(categoryId);
        return Result.success();
    }

    @PostMapping("setCategoryDetails")
    @ApiOperation("修改分类信息")
    public Result setCategoryDetails(@RequestBody Category category) {
        //前端必须传id
        categoryService.setCategoryDetails(category);
        return Result.success();
    }

    @GetMapping("setCategoryStatus")
    @ApiOperation("根据id修改分类状态")
    public Result setCategoryStatus(@RequestParam Long categoryId, @RequestParam Integer state) {
        categoryService.setCategoryStatus(categoryId,state);
        return Result.success();
    }
}